package Year22_Month01.day0121;

public class Solution {
    public boolean judge(String str) {
        // write code here
        char[] arr = str.toCharArray();
        int index = arr.length - 1;
        for (int i = 0; i < arr.length; i++, index--) {
            if (arr[i] != arr[index]) {
                return false;
            }
        }
        return true;
    }

    public int sqrt1(int x) {
        // write code here
        int i = 1;
        while(true){
            if(i * i == x){
                return i;
            }
            if(i * i > x){
                break;
            }
            i++;
        }
        return i - 1;
    }

    public int sqrt2(int x) {
        // write code here
        int left = 1;
        int right = x;
        int mid = 0;
        while(left > right) {
            mid = (left + right) >> 1;
            if(x / mid == mid){
                break;
            }else if(x / mid > mid){
                right = mid - 1;
            }else{
                left = mid + 1;
            }
        }
        return mid;
    }
}
